﻿using System;
using System.Collections.Generic;
using Ornament.Domain;
using Ornament.Messages.Contents.Stores;

namespace Ornament.Messages.Contents
{
    public interface IContent
    {
        object Value { get; set; }
        IStore Store { get; set; }
      

        /// <summary>
        /// Id may be of type string, int, custom type, etc.
        /// Setter is protected to allow unit tests to set this property via reflection and to allow 
        /// domain objects more flexibility in setting this for those objects with assigned IDs.
        /// </summary>
        Guid Id { get; set; }

        Dictionary<string, string> FillTemplateValue(Info info);
    }

    public abstract class Content : DomainObject<Guid>, IContent
    {
        #region IContent Members

        Guid IContent.Id
        {
            get { return base.Id; }
            set { base.Id = value; }
        }


        public virtual object Value { get; set; }

        public virtual IStore Store { get; set; }

     
        public virtual Dictionary<string, string> FillTemplateValue(Info info)
        {
            var pattern = new Dictionary<string, string>
                              {
                                  {"Id",info.Id.ToString()},
                                  {"Content", info.Content.Value.ToString()},
                                  {"Publisher", info.Publisher},
                                  {"CreateTime", info.CreateTime.ToString()},
                                  {"PublisherTime", info.PublishTime.ToString()}
                              };
            FillContentValue(info, pattern);
            return pattern;
        }

        #endregion

        /// <summary>
        /// fill key-value to valueMaps
        /// </summary>
        /// <param name="info"></param>
        /// <param name="valueMapns"></param>
        protected abstract void FillContentValue(Info info, Dictionary<string, string> valueMaps);


        public override int GetHashCode()
        {
            return (Value).GetHashCode()+Store.GetHashCode();
        }
    }
}